#ifndef _DS18B20_H_
#define _DS18B20_H_

#include "stm32f10x.h"
#include "board.h"

#define READ_DS18B20()        GPIO_ReadInputDataBit(GPIOB, DS18B20_BIT)

#define DIR_1WIRE_IN()        {DS18B20_PORT->CRL &= 0xFF0FFFFF;DS18B20_PORT->CRL |= 0x00400000;}
#define DIR_1WIRE_OUT()        {DS18B20_PORT->CRL &= 0xFF0FFFFF;DS18B20_PORT->CRL |= 0x00300000;}
#define CLR_OP_1WIRE()        GPIO_ResetBits(DS18B20_PORT, DS18B20_BIT)
#define SET_OP_1WIRE()        GPIO_SetBits(DS18B20_PORT, DS18B20_BIT)
#define CHECK_IP_1WIRE()    GPIO_ReadInputDataBit(DS18B20_PORT, DS18B20_BIT)

void write_1820(u8 x);
void reset_1wire();
void init_1820();
u8 read_1820(void);
void DS18B20_init(void);
void DS18B20_Convert(void);
s16 DS18B20_Read(void);
void delay_nus(vu32 nCount);

#endif
